<?php
class RequestHandler extends BaseRequestHandler
{
    protected static $instance;

    public static function GetInstance($timestart = 0)
    {
        return self::$instance ? self::$instance : self::$instance = new RequestHandler($timestart);
    }

    protected function LoadPage()
    {
        try
        {
            try
            {
                $this->controller = new PageController($this->url);
                return $this->controller->PageExisted();
            }
            catch (DBNoDefaultConnectionException $ex)
            {
                $this->RedirectToInstallPage();
                return false;
            }
        }
        catch (DBConnectionException $ex)
        {
            return false;
        }
    }

    public function RedirectToInstallPage()
    {
        $urls = explode(FS, $this->url);
        $controllerName = String::Pascalize($urls[0]);
        if ($controllerName != 'CmsInstall')
            self::Redirect(AppConfig::GetInstance()->URL_INSTALL);
    }

    public function PageNotFound()
    {
        header($_SERVER["SERVER_PROTOCOL"].' 404 Not Found');
        header('Status: 404 Not Found');
        $page = new PageController('page-not-found');
        echo $page->RenderPage();
        exit_app();
    }
}
?>
